//
//  StatusCell.swift
//  上海微博
//
//  Created by co on 16/3/2.
//  Copyright © 2016年 王南侠. All rights reserved.
//

import UIKit
import SnapKit
// 微博cell 
class StatusCell: UITableViewCell {
    
    /// 微博视图模型
    var viewModle:StatusViewModle? {
        didSet{
            // 设置数据
            originalView.viewModle = viewModle
            retwteedView .viewModel = viewModle
        }
    }

    // MARK: - 构造函数
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    // MARK: - 私有控件
    // 原创微博
    private let originalView: StatusOriginalView = StatusOriginalView()
    // 被转发微博
    private let retwteedView: StatusRetweetedView = StatusRetweetedView()
    // 工具栏
    private let toolbar:StatuToolbar = StatuToolbar()
    
    
}

extension StatusCell {
    
    private func setupUI(){
        
        // 1.设置背景颜色
        backgroundColor = UIColor.cz_colorWithHex(0xF2F2F2)
        // 2.添加控件
        contentView.addSubview(originalView)
        contentView.addSubview(retwteedView)
        contentView.addSubview(toolbar)
        
//        originalView.backgroundColor = UIColor.redColor()
        // 3.自动布局
        let margin = CZStatusCellLayout.margin
        originalView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(contentView)
            make.right.equalTo(contentView)
            make.top.equalTo(contentView).offset(margin)
        }
        
        retwteedView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(contentView)
            make.right.equalTo(contentView)
            make.top.equalTo(originalView.snp_bottom)
        }
        toolbar.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(contentView)
            make.right.equalTo(contentView)
            make.top.equalTo(retwteedView.snp_bottom)
            
            make.height.equalTo(36)
        }
        
        // 4.异步绘制
        self.layer.drawsAsynchronously = true
        
        //  删格式化  - 会将cell  的图层内容生成一张图层 并且缓存 在滚动中不在生成cell 的内容
        self.layer.shouldRasterize = true
        // 一定要设置分辨率
        self.layer.rasterizationScale = UIScreen.mainScreen().scale
        
    }
}